package com.ruoyi.project.business.workovertime.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.business.workovertime.entity.WorkOvertime;
import com.ruoyi.project.business.workovertime.request.ListWorkOvertimeRequest;
import com.ruoyi.project.business.workovertime.request.AddWorkOvertimeRequest;
import com.ruoyi.project.business.workovertime.response.WorkOvertimeResponse;
import com.ruoyi.project.business.workovertime.service.IWorkOvertimeService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.model.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 加班Controller
 * 
 * @author ${author}
 * @date 2024-04-23
 */
@RestController
@RequestMapping("/business/workovertime")
public class WorkOvertimeController extends BaseController {
    @Autowired
    private IWorkOvertimeService workOvertimeService;

    /**
     * 查询加班列表
     */
    @PreAuthorize("@ss.hasPermi('business:workovertime:list')")
    @GetMapping("/list")
    public TableDataInfo list(ListWorkOvertimeRequest request) {
        startPage();
        Long tenantId = getTenantId();
        List<WorkOvertimeResponse> list = workOvertimeService.selectWorkOvertimeList(request, tenantId);
        return getDataTable(list);
    }

    /**
     * 导出加班列表
     */
    @PreAuthorize("@ss.hasPermi('business:workovertime:export')")
    @Log(title = "加班", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ListWorkOvertimeRequest request) {
        Long tenantId = getTenantId();
        List<WorkOvertimeResponse> list = workOvertimeService.selectWorkOvertimeList(request, tenantId);
        ExcelUtil<WorkOvertimeResponse> util = new ExcelUtil<>(WorkOvertimeResponse.class);
        return util.exportExcel(list, "workovertime");
    }

    /**
     * 获取加班详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:workovertime:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(workOvertimeService.selectWorkOvertimeById(id));
    }

    /**
     * 新增加班
     */
    @PreAuthorize("@ss.hasPermi('business:workovertime:add')")
    @Log(title = "加班", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AddWorkOvertimeRequest request) {
        Long tenantId = getTenantId();
        Long operatorId = getUserId();
        return toAjax(workOvertimeService.insertWorkOvertime(request, operatorId, tenantId));
    }

    /**
     * 修改加班
     */
    @PreAuthorize("@ss.hasPermi('business:workovertime:edit')")
    @Log(title = "加班", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WorkOvertime workOvertime) {
        Long tenantId = getTenantId();
        Long operatorId = getUserId();
        return toAjax(workOvertimeService.updateWorkOvertime(workOvertime, operatorId, tenantId));
    }

    /**
     * 删除加班
     */
    @PreAuthorize("@ss.hasPermi('business:workovertime:remove')")
    @Log(title = "加班", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        Long tenantId = getTenantId();
        Long operatorId = getUserId();
        return toAjax(workOvertimeService.deleteWorkOvertimeByIds(ids, operatorId, tenantId));
    }
}
